import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'dva'
import { Row,Col,Card,Tabs } from 'antd'
import { routerRedux } from 'dva/router'
import List from './List'
import Search from './searchBottom'
import Header from './header'
import Modal from './modal'
import Details from './details'

const FileDestroy = ({location,dispatch,fileDestroy,loading}) =>{
	const { list,visible,menu,params,details,userList,pagination1,isNew,showDetails,info} = fileDestroy
	const { query, pathname } = location
//	console.log(isNew)
	
	const modalProps = {
		visible,
		details,
		userList,
		isNew,
		onOk(){
			dispatch({
				type:'fileDestroy/onModalOk',
				payload:{}
			})
		},
		onCancels(){
			dispatch({
				type:'fileDestroy/onCancels',
				payload:{}
			})
		},
		onComponent(payload){
//			console.log(payload)
			dispatch({
				type:'fileDestroy/applicationSave',
				payload:{
					...payload
				}
			})
		},	
		onComponentUpdate(payload){
//			console.log(payload)
			dispatch({
				type:'fileDestroy/applicationUpdate',
				payload:{
					...payload
				}
			})
		},
	}
	const listProps = {
		list,
		menu,
		pagination1,
		showModals(type){
			dispatch({
				type:'fileDestroy/showModal',
				payload:{
					name:type
				}
			})
		},
		showDet(params){
			dispatch({
				type:'fileDestroy/showDet',
				payload:{
					...params
				}
			})
		},
		onPageChange(page){
			const { query, pathname } = location
          	dispatch({
                type: 'fileDestroy/searchList',
                payload: {
                  ...params,
                  page: page.current,
                	  pageSize: page.pageSize,
                	  
                	  
                }
              })
	     },	
		showPage(payload){
			dispatch({
				type:'fileDestroy/showPage',
				payload:{
					...payload
				}
			})
		},
	}
	const headerProps = {
		menu,
		showMenu(id){
			dispatch({
				type:'fileDestroy/showMenu',
				payload:id
			})
		},
		changeType(key){
			let menu = key.menu
			dispatch(routerRedux.push({
				pathname:pathname,
				query:{
					...query,
					menu
				}
			}))
		},
		onSearch(params){
			dispatch({
				type:'fileDestroy/searchList',
				payload:{
					...params
				}
			})
		},
	}
	const searchProps = {
		menu,
		onSearch(params){
			dispatch({
				type:'fileDestroy/searchList',
				payload:{
					...params
				}
			})
		},
	}
	const detailsProps = {
		info,
		showList(){
			dispatch({
				type:'fileDestroy/showList',
				payload:{}
			})
		},
		onDeleteItem(id){
//			console.log(id)
			dispatch({
				type:'fileDestroy/delete',
				payload:{
					id:id
				}
			})
		},
		onEdit(payload){
//			console.log(payload)
			dispatch({
				type:'fileDestroy/applicationUpdate',
				payload:{
					...payload
				}
			})
		},
	}	
	
	return(
      <div className="content-inner" style={{backgroundColor:'transparent',padding:0}}>
    		<div style={{display:showDetails?'none':'block'}}>
	    		<Header {...headerProps}/>
	    		{menu == 0 ?
	    			<Search {...searchProps}/>:
	    			""
	    		}
	    	  	
	      	<List {...listProps}/>
	      	{visible && <Modal {...modalProps} />}
	    </div>  	
      	<div style={{display:showDetails?'block':'none'}}>
      		<Details {...detailsProps}/>
      	</div>
      	{/*<Modal />
	    {modalVisible && <ModalList {...contractModalProps}/>}*/}
      </div>		
	)
}

export default connect(({ fileDestroy, loading }) => ({ fileDestroy, loading }))(FileDestroy)
